# @author:Wei Junjie
# @time:2024/5/28 13:01
# @file wangyi.py
# --*--coding: utf-8 --*--
"""
网易邮箱登录
"""
import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains


# 设置webdriver option属性伪装成浏览器
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
options.add_experimental_option('useAutomationExtension', False)
# 实例化webdriver对象
driver = webdriver.Chrome(options=options)
driver.maximize_window()
driver.implicitly_wait(10)
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source": """
        Object.defineProperty(navigator, 'webdriver', {
          get: () => undefined
        })   """
})

# 登录163邮箱=>输入账号=>输入密码=>点击登录
driver.get("https://email.163.com/")
# 切换到iframe里面
driver.switch_to.frame(driver.find_elements(By.TAG_NAME, 'iframe')[0])
# 账号框
Account=driver.find_elements(By.CSS_SELECTOR, "#login-form>div>div>div>input")[0]
# 点击=>输入账号
ActionChains(driver).click(Account).send_keys('0234934819').perform()
# 密码框
Password=driver.find_elements(By.CSS_SELECTOR, "#login-form>div>div:nth-child(3)>div:nth-child(2)>input")[2]
# 点击=>输入密码
ActionChains(driver).double_click(Password).send_keys('z5723915478').perform()
# 点击登录按钮
driver.find_element(By.CSS_SELECTOR, "a#dologin").click()
# 设置等待时间
time.sleep(10)
# 截图
driver.get_screenshot_as_file('temp.png')
# 关闭driver
driver.close()

